/*
* 搜索相关的API请求
* */

import jsonp from 'common/js/jsonp';
import {commonParams,options} from "./config";
import axios from 'axios'

export function getHotKey () {
  const url = 'https://c.y.qq.com/splcloud/fcgi-bin/gethotkey.fcg'
  const data = Object.assign({},commonParams,{
    g_tk: 5381,
    uin: 0,
    platform: 'h5',
    needNewCode: 1,
  });
  return jsonp(url,data,options)
}

// 搜索歌曲歌手api
export function search (query,page,zhida,perpage) {
  const url = '/api/search';
  const data = Object.assign({},commonParams,{
    g_tk: 5381,
    w: query,
    p: page,
    catZhida: zhida ? 1 : 0,
    zhidaqu: 1,
    t: 0,
    flag: 1,
    ie: 'utf-8',
    sem: 1,
    aggr: 0,
    perpage,  // 请求的条数
    n: perpage, // 请求的条数
    remoteplace: 'txt.mqq.all',
    uin: 0,
    platform: 'h5',
    needNewCode: 1,
    _: + new Date(),
    format: 'json'
  });
  return axios.get(url,{
    params: data
  }).then((res) => {
    return Promise.resolve(res.data)
  })
}
